﻿using System.Security.Cryptography;
using OpenAiMobile.Util.Io;

namespace OpenAiMobile.Util.Security
{
    public static class SecurityHelper
    {
        public static byte[] Pad(byte[] buf, KeySizes keySize)
        {
            var num = buf.Length * 8;
            var length = 0;
            for (var minSize = keySize.MinSize; minSize <= keySize.MaxSize; minSize += keySize.SkipSize)
            {
                if (minSize >= num)
                {
                    length = minSize / 8;
                    break;
                }

                if (keySize.SkipSize == 0)
                {
                    break;
                }
            }

            if (length == 0)
            {
                length = keySize.MaxSize / 8;
            }

            if (buf.Length == length)
            {
                return buf;
            }

            var dst = new byte[length];
            dst.Write(0, buf);
            return dst;
        }
    }
}
